﻿using LoomDataEmulator.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;
using System.Collections.Generic;

namespace LoomDataEmulator.TestSuite
{
    
    
    /// <summary>
    ///This is a test class for FileProcessPoolTest and is intended
    ///to contain all FileProcessPoolTest Unit Tests
    ///</summary>
    [TestClass()]
    public class FileProcessPoolTest
    {
        private TestContext testContextInstance;
        private FileInfo fileToTest;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for FileProcessPool Constructor
        ///</summary>
        [TestMethod()]
        public void FileProcessPoolConstructorTest()
        {
            FileProcessPool target = new FileProcessPool();
            Assert.IsNotNull(target);
        }

        protected void CreateTestFile()
        {
            StreamWriter writer = new StreamWriter("C:\\TEMP\\test.txt");
            writer.Write("test");

            writer.Flush();
            writer.Close();
            writer.Dispose();

            fileToTest = new FileInfo("C:\\TEMP\\test.txt");
        }

        /// <summary>
        ///A test for AddFile
        ///</summary>
        [TestMethod()]
        public void AddFileTest()
        {
            this.CreateTestFile();

            FileProcessPool target = new FileProcessPool(); // TODO: Initialize to an appropriate value
            
            target.AddFile(fileToTest);

            this.DeleteTestFile();

            Assert.AreEqual(1, target.FilesPool.Count);
        }

        private void DeleteTestFile()
        {
            if (fileToTest != null)
                fileToTest.Delete();
        }

        /// <summary>
        ///A test for RemoveFile
        ///</summary>
        [TestMethod()]
        public void RemoveFileTest()
        {
            this.CreateTestFile();

            FileProcessPool target = new FileProcessPool(); // TODO: Initialize to an appropriate value
            target.AddFile(fileToTest);

            if(target.FilesPool.Count == 1)
            {
                target.RemoveFile(fileToTest);

                Assert.AreEqual(0, target.FilesPool.Count);
            }
            else
            {
                Assert.Fail("Could not add file");
            }

            this.DeleteTestFile();
        }

        /// <summary>
        ///A test for FilesPool
        ///</summary>
        [TestMethod()]
        public void FilesPoolTest()
        {
            FileProcessPool target = new FileProcessPool();
            Assert.IsNotNull(target.FilesPool);
        }
    }
}
